import util from "@/assets/js/util";
import $tip from "@/components/able_mod/AbToolTip"
import useDomOverlay from "./useDomOverlay";
export default function (fm, e) {
	if (fm.window) fm.window.setMap(null)
	if (util.isNull(e)) {
		$tip.message.open("没发现记录点",2500,"warning")
		fm.marker = []
		return fm
	} else if (e=='clear') {
		if (fm.marker && fm.marker.length) {
			fm.marker.forEach((dm)=>{
				dm.setMap(null)
			})
			fm.marker = null
		}
		return fm
	}
	let domMarker = useDomOverlay()
	let _marker = []
	
	for (let i in e) {
		e[i].markTime = util.formatGmt(e[i].markTime)
		let contentDom = `
			<div style="text-align: center;">
				<p style="margin: 0;padding: 0;display: flex;flex;flex-direction: column;
						background-color: rgba(200,200,200,0.5);padding: 5px;
						border-radius: 5px;box-shadow: 1px 1px 5px #ccc;">
					<b style="font-size: 12px;color: #666;">${e[i].markTime}</b>
					<i style="font-size: 12px;color: #666;">${e[i].title}</i>
				</p>
				<img 
					class="dom-overlay-click"
					src="${util.MARKER_IMG}" 
					style="width: 45px;height: 45px;cursor:pointer;"
				/>
			</div>
		`
		e[i].markTime = e[i].markTime.split(' ')[1]
		contentDom = `
			<div style="position: relative;">
				<b style="display: block;font-size: 12px;color: #666;
					background-color: rgba(200,200,200,0.9);padding: 1px;
					border-radius: 3px;box-shadow: 1px 1px 1px #ccc;
					position: absolute;bottom: -5px;;left: 30px;">${e[i].markTime}</b>
				<img 
					class="dom-overlay-click"
					src="${util.MARKER_IMG}" 
					style="width: 45px;height: 45px;cursor:pointer;"
				/>
			</div>
		`
		// contentDom = `
		// 	<img 
		// 		class="dom-overlay-click"
		// 		src="${util.MARKER_IMG}" 
		// 		style="width: 45px;height: 45px;cursor:pointer;"
		// 	/>
		// `
		let m = new domMarker({
			map:fm.map,
			position: new TMap.LatLng(e[i].latitude, e[i].longitude),
			content: contentDom,
			data: e[i]
		})
		_marker.push(m)
	}
	// console.log(fm.marker)
	if (fm.marker) {
		fm.marker.forEach((dm)=>{
			dm.setMap(null)
		})
	}
	fm.marker = _marker
	fm.map.panTo(new TMap.LatLng(e[0].latitude, e[0].longitude))

	return fm
}